/**
 * 列表型数据转化树形
*/
export const transListToTreeData = (list, pid, isDeep = true) => {
  if (isDeep) { list = JSON.parse(JSON.stringify(list)) }

  const map = new Map()
  for (const item of list) {
    if (map.has(item.pid)) {
      map.get(item.pid).push(item)
    } else {
      map.set(item.pid, [item])
    }
  }

  for (const item of list) {
    if (map.has(item.id)) {
      item.children = map.get(item.id)
    }
  }

  return list.filter(item => item.pid === pid)
}
